package cn.springboot.erp.commons;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
@Data
@ApiModel("ResponseResult")
public class ResponseResult {


    // 验证码
    @ApiModelProperty(value = "验证码",example = "200")
    private Integer code;

    // 提示信息
    @ApiModelProperty(value = "响应信息",example = "认证成功")
    private String msg;

    // 相应数据
    @ApiModelProperty(value = "响应数据",example = "{code:200,msg:'认证成功'")
    private HashMap<String , Object> data = new HashMap<>();

    public ResponseResult(){}

    // 成功
    public static ResponseResult Success(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(ResponseState.SUCCESS.getCode());
        responseResult.setMsg(ResponseState.SUCCESS.getMessage());
        return responseResult;
    }

    // fail 错误
    public static ResponseResult Fail(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(ResponseState.FAIL.getCode());
        responseResult.setMsg(ResponseState.FAIL.getMessage());
        return responseResult;
    }

    // error 异常
    public static ResponseResult Error(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(ResponseState.ERROR.getCode());
        responseResult.setMsg(ResponseState.ERROR.getMessage());
        return responseResult;
    }



    public ResponseResult code(Integer code){
        this.code = code;
        return this;
    }

    public ResponseResult msg(String message){
        this.msg=message;
        return this;
    }

    public ResponseResult data(String key ,Object value){
        this.data.put(key,value);
        return this;
    }
}
